#!/bin/sh

#if [ ! $# -eq 5 ]
#then
#    echo "Usage: deploy_ebsu.sh mp_user mp_pass mp_host sut_eth sut_ip"
#    exit -1
#fi

CUR_PWD="$PWD"

#EBSU_SRC_DIR="/home/dahai/oslo-ebsu/ebsu-svn"
EBSU_SRC_DIR="/home/dahai/oslo-ebsu/binaries"
EBSU_DST_DIR="\\"

TMP_USER="root"
TMP_PASS="iforgot"
TMP_HOST="rx4640-8-mp.test"

TGT_IP="10.0.0.195"
TGT_ETH="0"

FTP_USER="dahai"
FTP_PASS="dahai"
FTP_HOST="10.0.0.2"
FTP_SDIR="$EBSU_SRC_DIR"

RPC="./rpc.exp"
if [ ! -f "$RPC" -o ! -f "/usr/bin/expect" ]
then
    echo "Please Have \"expect\" install on this host"
    echo "AND put \"$RPC\" in this directory!"
    exit -1
fi

function get_mkdir_list()
{
    cd "$EBSU_SRC_DIR"
    find "./" -type d | awk -F '/' 'BEGIN{i=0}{ i=i+1; if (i>1) { printf("-fm \""); for (i=2;i<=NF;i++) {printf("\\%s",$i)} printf("\" ") } }'
    cd "$CUR_PWD"
}

function get_ftpfile_list()
{
    cd "$EBSU_SRC_DIR"
    find "./" -type f | awk -F '/' 'BEGIN{i=0}{ i=i+1; if (i>1) { printf("-fg \""); for (i=2;i<NF;i++) {printf("%s/",$i)} printf("%s\" ", $i) } }'
    cd "$CUR_PWD"
}


$RPC atmn -n $TMP_USER -p $TMP_PASS -h $TMP_HOST -ip $TGT_IP -de $TGT_ETH

$RPC tmp -n $TMP_USER -p $TMP_PASS -h $TMP_HOST -x "rm -q \\EFI"

$RPC mftp -n $TMP_USER -p $TMP_PASS -h $TMP_HOST -s $FTP_SDIR -d $EBSU_DST_DIR -fn $FTP_USER -fp $FTP_PASS -fh $FTP_HOST `get_mkdir_list` `get_ftpfile_list`


